home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ASME's Mechanical Engine…ing Toolkit 1997 December
/
ASME's Mechanical Engineering Toolkit 1997 December.iso
/
c_lang
/
varinc.lzh
/
PAGE264.C
< prev
next >
Wrap
C/C++ Source or Header
|
1979-11-30
|
1KB
|
32 lines
#define DELIM '|' /* delimiter to separate fields of a record */
/****************************************************************************/
/* strfld() copies a field from a record to a separate string and returns */
/* the starting address of the target, to_str. */
/****************************************************************************/
char *strfld(to_str, from_rec, fld_num);
char to_str[]; /* target string to copy field to */
char from_rec[]; /* record string to copy field from */
short fld_num; /* field number to copy */
{
short ifrom, ito; /* indices into from_rec and to_str */
/* Skip over (fld_num - 1) delimiters to the field to copy. */
for (ifrom = 0; --fld_num && from_rec[ifrom] != '\0';)
{
while (from_rec[ifrom] != '\0' && from_rec[ifrom] != DELIM)
++ifrom;
if (from_rec[ifrom] == DELIM)
++ifrom;
}
/* Copy field from from_rec to to_str. */
for (ito = 0; from_rec[ifrom] != '\0' && from_rec[ifrom] != '\n'
&& from_rec[ifrom] != DELIM; ++ifrom, ++ito)
to_str[ito] = from_rec[ifrom]; /* Copy a character to to_str. */
to_str[ito] = '\0';
return (&to_str[0]);
}